
cd "`c(pwd)'"   // Set working directory to wherever the user placed "replication_package"

* Define global paths relative to the main directory
global main_dir "`c(pwd)'"
global data_dir "$main_dir/data_analysis"
global rawdata_dir "$main_dir/data_raw"
global tables_dir "$main_dir/tables"

* Load data
cd "$data_dir/"

use bygvkey_COW, clear
sort gvkey year
order gvkey year

collapse (max) COW, by(gvkey year)
drop if COW==.

sort gvkey year
gen bin=100
by gvkey: replace bin=30 if COW[_n+30]==1 & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n+24]!=1 & COW[_n+25]!=1 & COW[_n+26]!=1 & COW[_n+27]!=1 & COW[_n+28]!=1 & COW[_n+29]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=29 if COW[_n+29]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n+24]!=1 & COW[_n+25]!=1 & COW[_n+26]!=1 & COW[_n+27]!=1 & COW[_n+28]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=28 if COW[_n+28]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n+24]!=1 & COW[_n+25]!=1 & COW[_n+26]!=1 & COW[_n+27]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=27 if COW[_n+27]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n+24]!=1 & COW[_n+25]!=1 & COW[_n+26]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=26 if COW[_n+26]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n+24]!=1 & COW[_n+25]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=25 if COW[_n+25]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n+24]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=24 if COW[_n+24]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n+23]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=23 if COW[_n+23]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n+22]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=22 if COW[_n+22]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n+21]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=21 if COW[_n+21]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n+20]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=20 if COW[_n+20]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n+19]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=19 if COW[_n+19]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n+18]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=18 if COW[_n+18]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n+17]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=17 if COW[_n+17]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n+16]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=16 if COW[_n+16]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n+15]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=15 if COW[_n+15]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n+14]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=14 if COW[_n+14]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n+13]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=13 if COW[_n+13]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n+12]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=12 if COW[_n+12]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n+11]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=11 if COW[_n+11]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n+10]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=10 if COW[_n+10]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n+9]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=9 if COW[_n+9]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n+8]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=8 if COW[_n+8]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n+7]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=7 if COW[_n+7]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n+6]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=6 if COW[_n+6]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n+5]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=5 if COW[_n+5]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n+4]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=4 if COW[_n+4]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n+3]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=3 if COW[_n+3]==1  & COW!=1 & COW[_n+1]!=1 & COW[_n+2]!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=2 if COW[_n+2]==1  & COW!=1 & COW[_n+1]!=1  & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=1 if COW[_n+1]==1  & COW!=1 & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=0 if COW==1  & COW[_n-1]!=1 & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-1 if COW[_n-1]==1  & COW[_n-2]!=1 & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-2 if COW[_n-2]==1  & COW[_n-3]!=1 & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-3 if COW[_n-3]==1  & COW[_n-4]!=1 & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-4 if COW[_n-4]==1  & COW[_n-5]!=1 & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-5 if COW[_n-5]==1  & COW[_n-6]!=1 & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-6 if COW[_n-6]==1  & COW[_n-7]!=1 & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-7 if COW[_n-7]==1  & COW[_n-8]!=1 & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-8 if COW[_n-8]==1  & COW[_n-9]!=1 & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-9 if COW[_n-9]==1  & COW[_n-10]!=1 & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-10 if COW[_n-10]==1  & COW[_n-11]!=1 & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-11 if COW[_n-11]==1  & COW[_n-12]!=1 & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-12 if COW[_n-12]==1  & COW[_n-13]!=1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-13 if COW[_n-13]==1 & COW[_n-14]!=1 & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-14 if COW[_n-14]==1  & COW[_n-15]!=1 & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-15 if COW[_n-15]==1  & COW[_n-16]!=1 & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-16 if COW[_n-16]==1  & COW[_n-17]!=1 & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-17 if COW[_n-17]==1  & COW[_n-18]!=1 & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-18 if COW[_n-18]==1  & COW[_n-19]!=1 & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-19 if COW[_n-19]==1  & COW[_n-20]!=1 & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-20 if COW[_n-20]==1  & COW[_n-21]!=1 & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-21 if COW[_n-21]==1  & COW[_n-22]!=1 & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-22 if COW[_n-22]==1  & COW[_n-23]!=1 & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-23 if COW[_n-23]==1  & COW[_n-24]!=1 & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-24 if COW[_n-24]==1  & COW[_n-25]!=1 & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-25 if COW[_n-25]==1  & COW[_n-26]!=1 & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-26 if COW[_n-26]==1  & COW[_n-27]!=1 & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-27 if COW[_n-27]==1  & COW[_n-28]!=1 & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-28 if COW[_n-28]==1  & COW[_n-29]!=1 & COW[_n-30]!=1

by gvkey: replace bin=-29 if COW[_n-29]==1  & COW[_n-30]!=1

by gvkey: replace bin=-30 if COW[_n-30]==1 





tab bin
label var bin "27 = will be treated 27 years from now; 26 = will be treated 26 years from now; 25 = will be treated 25 years from now; ... ; 1 = it will be treated next year ; 0= treated this present year; -1 = was treated on eyear ago; -2 = was treated two years ago; ... ; -19 = was treated 19 years ago; 100 = never treated"

keep gvkey year bin
save cow_bins, replace

************************************************************************************
************************************************************************************
************************************************************************************


use tnic2_data, clear
rename gvkey1 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey1
rename gvkey2 gvkey
joinby gvkey year using sample_od, unmatched(master)
drop if _merge!=3
drop _merge
rename gvkey gvkey2
g tnpeers4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace tnpeers4=0 if _merge!=3
drop _merge score
rename gvkey1 gvkey
drop gvkey2
collapse (sum)  tnpeers4 , by(year gvkey)
save temp2_2, replace
******************************************************************************




******************************************************************************
******************************************************************************
* DENSITY when bin==30
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=30
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin30
save od_density_bin30, replace



******************************************************************************
* DENSITY when bin==29
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=29
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin29
save od_density_bin29, replace



******************************************************************************
* DENSITY when bin==28
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=28
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin28
save od_density_bin28, replace



******************************************************************************
* DENSITY when bin==27
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=27
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin27
save od_density_bin27, replace



******************************************************************************
* DENSITY when bin==26
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=26
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin26
save od_density_bin26, replace



******************************************************************************
* DENSITY when bin==25
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=25
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin25
save od_density_bin25, replace



******************************************************************************
* DENSITY when bin==24
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=24
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin24
save od_density_bin24, replace



******************************************************************************
* DENSITY when bin==23
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=23
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin23
save od_density_bin23, replace



******************************************************************************
* DENSITY when bin==22
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=22
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin22
save od_density_bin22, replace



******************************************************************************
* DENSITY when bin==21
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=21
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin21
save od_density_bin21, replace



******************************************************************************
* DENSITY when bin==20
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=20
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin20
save od_density_bin20, replace



******************************************************************************
* DENSITY when bin==19
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=19
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin19
save od_density_bin19, replace



******************************************************************************
* DENSITY when bin==18
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=18
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin18
save od_density_bin18, replace



******************************************************************************
* DENSITY when bin==17
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=17
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin17
save od_density_bin17, replace



******************************************************************************
* DENSITY when bin==16
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=16
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin16
save od_density_bin16, replace



******************************************************************************
* DENSITY when bin==15
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=15
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin15
save od_density_bin15, replace



******************************************************************************
* DENSITY when bin==14
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=14
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin14
save od_density_bin14, replace



******************************************************************************
* DENSITY when bin==13
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=13
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin13
save od_density_bin13, replace



******************************************************************************
* DENSITY when bin==12
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=12
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin12
save od_density_bin12, replace



******************************************************************************
* DENSITY when bin==11
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=11
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin11
save od_density_bin11, replace



******************************************************************************
* DENSITY when bin==10
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=10
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin10
save od_density_bin10, replace



******************************************************************************
* DENSITY when bin==9
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=9
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin9
save od_density_bin9, replace



******************************************************************************
* DENSITY when bin==8
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=8
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin8
save od_density_bin8, replace



******************************************************************************
* DENSITY when bin==7
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=7
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin7
save od_density_bin7, replace



******************************************************************************
* DENSITY when bin==6
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=6
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin6
save od_density_bin6, replace



******************************************************************************
* DENSITY when bin==5
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=5
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin5
save od_density_bin5, replace



******************************************************************************
* DENSITY when bin==4
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=4
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin4
save od_density_bin4, replace



******************************************************************************
* DENSITY when bin==3
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=3
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin3
save od_density_bin3, replace



******************************************************************************
* DENSITY when bin==2
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=2
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin2
save od_density_bin2, replace



******************************************************************************
* DENSITY when bin==1
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=1
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin1
save od_density_bin1, replace



******************************************************************************
* DENSITY when bin==0
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=0
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin0
save od_density_bin0, replace



******************************************************************************
* DENSITY when bin==-30
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-30
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_30
save od_density_bin_30, replace



******************************************************************************
* DENSITY when bin==-29
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-29
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_29
save od_density_bin_29, replace



******************************************************************************
* DENSITY when bin==-28
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-28
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_28
save od_density_bin_28, replace



******************************************************************************
* DENSITY when bin==-27
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-27
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_27
save od_density_bin_27, replace



******************************************************************************
* DENSITY when bin==-26
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-26
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_26
save od_density_bin_26, replace



******************************************************************************
* DENSITY when bin==-25
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-25
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_25
save od_density_bin_25, replace



******************************************************************************
* DENSITY when bin==-24
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-24
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_24
save od_density_bin_24, replace



******************************************************************************
* DENSITY when bin==-23
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-23
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_23
save od_density_bin_23, replace



******************************************************************************
* DENSITY when bin==-22
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-22
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_22
save od_density_bin_22, replace



******************************************************************************
* DENSITY when bin==-21
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-21
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_21
save od_density_bin_21, replace



******************************************************************************
* DENSITY when bin==-20
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-20
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_20
save od_density_bin_20, replace



******************************************************************************
* DENSITY when bin==-19
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-19
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_19
save od_density_bin_19, replace



******************************************************************************
* DENSITY when bin==-18
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-18
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_18
save od_density_bin_18, replace



******************************************************************************
* DENSITY when bin==-17
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-17
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_17
save od_density_bin_17, replace



******************************************************************************
* DENSITY when bin==-16
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-16
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_16
save od_density_bin_16, replace



******************************************************************************
* DENSITY when bin==-15
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-15
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_15
save od_density_bin_15, replace



******************************************************************************
* DENSITY when bin==-14
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-14
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_14
save od_density_bin_14, replace



******************************************************************************
* DENSITY when bin==-13
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-13
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_13
save od_density_bin_13, replace



******************************************************************************
* DENSITY when bin==-12
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-12
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_12
save od_density_bin_12, replace



******************************************************************************
* DENSITY when bin==-11
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-11
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_11
save od_density_bin_11, replace



******************************************************************************
* DENSITY when bin==-10
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-10
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_10
save od_density_bin_10, replace



******************************************************************************
* DENSITY when bin==-9
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-9
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_9
save od_density_bin_9, replace



******************************************************************************
* DENSITY when bin==-8
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-8
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_8
save od_density_bin_8, replace



******************************************************************************
* DENSITY when bin==-7
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-7
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_7
save od_density_bin_7, replace



******************************************************************************
* DENSITY when bin==-6
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-6
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_6
save od_density_bin_6, replace



******************************************************************************
* DENSITY when bin==-5
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-5
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_5
save od_density_bin_5, replace



******************************************************************************
* DENSITY when bin==-4
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-4
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_4
save od_density_bin_4, replace



******************************************************************************
* DENSITY when bin==-3
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-3
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_3
save od_density_bin_3, replace



******************************************************************************
* DENSITY when bin==-2
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-2
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_2
save od_density_bin_2, replace



******************************************************************************
* DENSITY when bin==-1
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=-1
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin_1
save od_density_bin_1, replace



******************************************************************************
* DENSITY when bin==100
use overlapping_directors_pop_double, clear
drop if gvkey1==gvkey2
g overdirs4=1
capture drop _merge
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace overdirs4=0 if _merge!=3
drop _merge score
rename gvkey2 gvkey
joinby gvkey year using cow_bins, unmatched(master)
drop _merge
rename gvkey gvkey2
*******************************
	replace overdirs4=0 if bin!=100
*******************************
rename gvkey1 gvkey
drop gvkey2
collapse (sum)   overdirs4  , by(year gvkey)
save temp_2, replace
*Put the two parts together...
use temp2_2, clear
merge year gvkey using temp_2
drop if _merge ==2
drop _merge
replace overdirs4=0 if overdirs4==.
g odrat4=overdirs4/tnpeers4
sort year gvkey
save jh_overdirs2odbin, replace
*NETWORK DENSITY
use tnic2_data, clear
drop if gvkey1==gvkey2
rename gvkey2 gvkey
sort year gvkey
joinby year gvkey using jh_overdirs2odbin, unmatched(master)
keep if _merge==3
drop _merge score
rename gvkey gvkey2
keep gvkey1 gvkey2 year odrat4
sort gvkey1 gvkey2 year
joinby gvkey1 gvkey2 year using tnic4_data, unmatched(master)
replace odrat4=. if _merge!=3
drop _merge score
rename gvkey1 gvkey
sum
collapse (mean) odrat4 , by(year gvkey)
sort year gvkey
rename odrat4 oddensity4_bin100
save od_density_bin100, replace






